﻿using System;
using Landpy.CruiseControlNet.ConfigurationSidekick.ConfigTreeModule;
using Landpy.CruiseControlNet.ConfigurationSidekick.ParserModule;

namespace Landpy.CruiseControlNet.ConfigurationSidekick.ConfigPropertyModule
{
    internal class RolePermissonSecurityUserHandler : GetPropertiesHandler
    {
        public override object GetPropertiesObject(GetPropertiesContext getPropertiesContext)
        {
            var treeNodeIndentity = this.GetTreeNodeIndentity(getPropertiesContext);
            if ((treeNodeIndentity.Type & TreeNodeType.InternalRolePermissonSecurityUser) != TreeNodeType.Unknow)
            {
                InternalRolePermissonSecurityUserKey internalRolePermissonSecurityUserKey =
                    InternalRolePermissonSecurityUserKeyUtil.GetKey(treeNodeIndentity.Key);
                var querySecurityUser =
                    this.SecurityUserRepository.GetInternalRolePermissonSecurityUserById(
                        getPropertiesContext.CruiseControl, internalRolePermissonSecurityUserKey.PermissionId, internalRolePermissonSecurityUserKey.Id);
                return querySecurityUser;
            }
            if ((treeNodeIndentity.Type & TreeNodeType.ProjcectRolePermissonSecurityUser) != TreeNodeType.Unknow)
            {
                throw new NotImplementedException();
            }
            return this.Successor.GetPropertiesObject(getPropertiesContext);
        }
    }
}